<template>
  <el-dialog
    :visible.sync="visible"
    :title="disabled? '详情' : $t('update')"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="50%"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmitHandle()"
      :label-width="$i18n.locale === 'en-US' ? '120px' : '120px'"
        :disabled="disabled"
    >
      <el-row :gutter="30">
        <el-col :span="24">
          <el-form-item label="电话" prop="phone">
            <el-input v-model="dataForm.phone" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="内容" prop="content">
            <el-input type="textarea" rows="3" v-model="dataForm.content" disabled>
            </el-input>
          </el-form-item>
        </el-col>
        
        <el-col :span="24">
          <el-form-item label="图片" prop="pic">
             <el-image
              v-if="dataForm.pic"
      style="width: 150px; height: 150px"
      :src="dataForm.pic"
      fit="contain" :preview-src-list="[dataForm.pic]"></el-image>
          </el-form-item>
        </el-col>
         <el-col :span="24">
          <el-form-item label="负责人" prop="head">
            {{dataForm.realName}}
             <!-- <el-select v-model="dataForm.head" placeholder="请选择" disabled clearable>
    <el-option
      v-for="item in headList"
      :key="item.id"
      :label="item.username"
      :value="item.id">
    </el-option>
  </el-select> -->
          </el-form-item>
        </el-col>
         <el-col :span="24">
          <el-form-item label="处理结果" prop="reply">
            <el-input type="textarea" rows="3" v-model="dataForm.reply" >
            </el-input>
          </el-form-item>
        </el-col>
         <el-col :span="24">
          <el-form-item label="状态" prop="state">
            <el-radio-group v-model="dataForm.state">
                  <el-radio :label="0">派单中</el-radio>
                  <el-radio :label="1">已结束 </el-radio>
                </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template slot="footer" v-if="!disabled">
      <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{
        $t("confirm")
      }}</el-button>
    </template>
  </el-dialog>
</template>

<script>
import debounce from "lodash/debounce";
export default {
  data() {
    return {
      visible: false,
      headList:[],
      dataForm: {
        id: "",
        head:"",
      },
    };
  },
  props:['disabled'],
  computed: {
    dataRule() {
      return {
        
      };
    },
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        if (this.dataForm.id) {
          this.getHeadData();
          this.getInfo();
        }
      });
    },
    getHeadData(){
      this.$http.get('/scenic/complaintrecommendation/userList').then(res=>{
        this.headList=res.data.data||[];
      })
    },
    //获取信息
    getInfo() {
       console.log(this.dataForm.id)
      this.$http
        .get("/scenic/workOrder/" + this.dataForm.id)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.dataForm = {
            ...this.dataForm,
            ...res.data,
          };
         
        })
        .catch(() => {});
    },
    // 表单提交
    dataFormSubmitHandle: debounce(
      function () {
        this.$refs["dataForm"].validate((valid) => {
          if (!valid) {
            return false;
          }
         
          this.$http.put(
            "/scenic/workOrder",
            this.dataForm
          )
            .then(({ data: res }) => {
              if (res.code !== 0) {
                return this.$message.error(res.msg);
              }
              this.$message({
                message: this.$t("prompt.success"),
                type: "success",
                duration: 500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                },
              });
            })
            .catch(() => {});
        });
      },
      1000,
      { leading: true, trailing: false }
    ),
  },
};
</script>
<style scoped lang="scss">
h3 {
  padding: 30px 0 15px;
  width: 94%;
  margin: 0 auto 30px;
  border-bottom: 1px solid #ddd;
  color: #303133;
  font-size: 22px;
  overflow: hidden;
}
.rooms .item{
  display: inline-block;
  margin-right: 15px;
  position: relative;
  .el-icon-error{
    position: absolute;
    right: 6px;
    top: -6px;
    font-size: 20px;
    color: #dd0606;
  }
}

</style>
